home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
9-Digit Zip Code Directory
/
9-Digit Zip Code Directory (American Business Information) (ABIZIP-12).ISO
/
z4src.zip
/
BSPASSWD.C
< prev
next >
Wrap
C/C++ Source or Header
|
1993-05-20
|
4KB
|
113 lines
//----------------------------------------------------------------------------
// MODULE DESCRIPTION
//
// Module: bspasswd.c
// Title: Base Library
// Notice: Copyright (c) 1991-1993, John Weeder, All Rights Reserved.
// Copyright (c) 1993. All rights reserved.
// This module contains proprietary information and should be
// treated as confidential.
//
//----------------------------------------------------------------------------
// MAINTENANCE HISTORY
//
// $Workfile$
// $Revision$
// $Author$
// $Date$
// $Log$
//
//----------------------------------------------------------------------------
// MODULE NARRATIVE
//
//
// This module contains code to handle passwords. Passwords are always stored
// externally as 4 byte key values. Internally a password consists of two
// ASCII zero terminated strings which are combined form the key. Passwords
// are verified by re-submitting the strings ands key. Normally the two
// strings are a password and user id.
//
// The code in this module should be written entirely in C.
// Do not use any C++ constructs.
//
// This module is portable to:
// DOS 3.X+
// MS Windows 3.X+
// OS/2 2.X+
// OS/2 2.0 PM
// SCO UNIX.
//
// The following compilers are supported:
// MSC 6.0A
// MSC/C++ 7.0
// Borland C++ 3.1 for DOS
// Borland C++ 1.0 for OS/2 2.X
// SCO UNIX cc
//
//----------------------------------------------------------------------------
#include <bs.h>
//----------------------------------------------------------------------------
// Description: Get password key.
// NOTE: Order of password strings is significant!!
// Parameters: pcsz1, pcsz2 Two strings to generate passowrd from.
// Returns: Key
//----------------------------------------------------------------------------
ULONG FN_E PasswordGet(PCSZ pcsz1, PCSZ pcsz2)
{
CRC crc = CrcCalc((PBYTE)pcsz1, strlen(pcsz1) + 1);
crc = CrcCalcAppend((PBYTE)pcsz2, strlen(pcsz2) + 1, crc);
return (ULONG)crc;
}
//----------------------------------------------------------------------------
// Description: Verify password key.
// NOTE: Order of password strings is significant!!
// Parameters: pcsz1, pcsz2 Two strings to generate passowrd from.
// Returns: TRUE if password is verified
//----------------------------------------------------------------------------
BOOL FN_E PasswordVerify(PCSZ pcsz1, PCSZ pcsz2, ULONG ulKey)
{
ULONG ulKey2 = PasswordGet(pcsz1, pcsz2);
return ulKey == ulKey2;
}
//----------------------------------------------------------------------------
// Description: Run standard test suite
// Parameters: sTest Test to run.
// 0 Run all default tests (except).
// Returns: TRUE if successful.
//----------------------------------------------------------------------------
#if COMPILE_TEST
BOOL FN PasswordTest(SHORT sTest)
{
static PCSZ pcsz1 = "John Marvin Weeder";
static PCSZ pcsz2 = "Carol Sue Weeder";
static PCSZ pcsz3 = "John Marvin Weedes";
ULONG ulKey = PasswordGet(pcsz1, pcsz2);
NOTUSED(sTest);
Output(" 1: %s\n 2: %s\nKey: %08lX\n",
pcsz1, pcsz2, ulKey);
if (!PasswordVerify(pcsz1, pcsz2, ulKey))
return FALSE;
if (PasswordVerify(pcsz2, pcsz1, ulKey))
return FALSE;
if (PasswordVerify(pcsz1, pcsz3, ulKey))
return FALSE;
return TRUE;
}
#endif
//----------------------------------------------------------------------------
//------------------------------- End of File --------------------------------
//----------------------------------------------------------------------------